package com.ruoyi.teacher.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teacher.domain.TEssay;
import com.ruoyi.teacher.service.ITEssayService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 论文信息集Controller
 *
 * @author xiangzy
 * @date 2022-05-10
 */
@Api(tags = "论文管理")
@RestController
@RequestMapping("/teacher/essay")
public class TEssayController extends BaseController
{
    @Autowired
    private ITEssayService tEssayService;

    /**
     * 查询论文信息集列表
     */
    @ApiOperation(value = "查询论文信息集列表")
    @PreAuthorize("@ss.hasPermi('teacher:essay:list')")
    @GetMapping("/list")
    public TableDataInfo list(TEssay tEssay)
    {
        startPage();
        List<TEssay> list = tEssayService.selectTEssayList(tEssay);
        return getDataTable(list);
    }

    /**
     * 通过A00查询论文信息列表
     */
    @ApiOperation(value = "通过A00查询论文信息列表")
    @PreAuthorize("@ss.hasPermi('teacher:essay:list')")
    @GetMapping("/listByA00")
    public TableDataInfo listByA00(@RequestParam Long A00)
    {
        List<TEssay> list = tEssayService.selectTEssayListByA00(A00);
        logger.info("通过A00查询论文信息列表为{}",list);
        return getDataTable(list);
    }

    /**
     * 导出论文信息集列表
     */
    @ApiOperation(value = "导出论文信息集列表")
    @PreAuthorize("@ss.hasPermi('teacher:essay:export')")
    @Log(title = "论文信息集", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TEssay tEssay)
    {
        List<TEssay> list = tEssayService.selectTEssayList(tEssay);
        ExcelUtil<TEssay> util = new ExcelUtil<TEssay>(TEssay.class);
        return util.exportExcel(list, "essay");
    }

    /**
     * 获取论文信息集详细信息
     */
    @ApiOperation(value = "获取论文信息集详细信息")
    @PreAuthorize("@ss.hasPermi('teacher:essay:query')")
    @GetMapping(value = "/{recordid}")
    public AjaxResult getEssayInfo(@PathVariable("recordid") Long recordid)
    {
        TEssay  tEssay= tEssayService.selectTEssayById(recordid);
        logger.info("论文的作者列表为{}",tEssay.getTEssayAuthorList());
        return AjaxResult.success(tEssay);
    }

    /**
     * 新增论文信息集
     */
    @PreAuthorize("@ss.hasPermi('teacher:essay:add')")
    @Log(title = "论文信息集", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TEssay tEssay)
    {
        return toAjax(tEssayService.insertTEssay(tEssay));
    }

    /**
     * 修改论文信息集
     */
    @PreAuthorize("@ss.hasPermi('teacher:essay:edit')")
    @Log(title = "论文信息集", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TEssay tEssay)
    {
        return toAjax(tEssayService.updateTEssay(tEssay));
    }

    /**
     * 删除论文信息集
     */
    @PreAuthorize("@ss.hasPermi('teacher:essay:remove')")
    @Log(title = "论文信息集", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordids}")
    public AjaxResult remove(@PathVariable Long[] recordids)
    {
        return toAjax(tEssayService.deleteTEssayByIds(recordids));
    }
}
